package pers.qianyu.month_202012.date_20201228;

import java.util.*;

import static java.lang.Math.*;

/**
 * 5. 多重背包问题 II
 * https://www.acwing.com/problem/content/5/
 * - 使用二进制优化多重背包
 *
 * @author mizzle rain
 * @date 2020年12月28日16:28:30
 */
public class BagMultipleTwo {
    private int N;
    private int V;
    // 体积
    private int[] v;
    // 价值
    private int[] w;
    // 个数
    private int[] s;

    public void input() {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        N = Integer.parseInt(line[0]);
        V = Integer.parseInt(line[1]);
        v = new int[N];
        w = new int[N];
        s = new int[N];
        for (int i = 0; i < N; i++) {
            v[i] = sc.nextInt();
            w[i] = sc.nextInt();
            s[i] = sc.nextInt();
        }
        sc.close();
    }

    private static class Good {
        int volume;
        int weight;

        Good(int volume, int weight) {
            this.volume = volume;
            this.weight = weight;
        }
    }

    public int solve() {
        ArrayList<Good> goods = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            int volume = v[i];
            int weight = w[i];
            int size = s[i];
            for (int j = 1; j <= size; j *= 2) {
                size -= j;
                goods.add(new Good(volume * j, weight * j));
            }
            if (size > 0) {
                goods.add(new Good(volume * size, weight * size));
            }
        }
        int[] dp = new int[V + 1];
        for (Good good : goods) {
            for (int i = V; i >= good.volume; i--) {
                dp[i] = max(dp[i], dp[i - good.volume] + good.weight);
            }
        }
        return dp[V];
    }

    public static void main(String[] args) {
        BagMultipleTwo bag = new BagMultipleTwo();
        bag.input();
        int result = bag.solve();
        System.out.println(result);
    }
}
